<?php

/*
 * ************************************************* 
 * Created on :2012-5-2 15:55:59
 * Encoding   :UTF-8
 * Description:
 * 
 * @Author @lqs <soso2501@gmail.com>
 * @WAP_WEIBO (C)1996-2099 SINA Inc. 
 * ************************************************
 */

class Msg {

    static $talbe = 'message';

    public static function send($to, $title, $content) {
        if (empty($to) || empty($title) || empty($content))
            return false;
        $data = array("title" => $title, "content" => $content, "from" => $GLOBALS['user']->userid,
            "to" => $to, "createtime" => date("Y-m-d H:i:s"), "read" => "N", "del" => "N");
        return DB::Insert(self::$talbe, $data);
    }

    public static function read($id) {
        if (empty($id))
            return false;
        $r = DB::GetTableRow(self::$talbe, array("id" => $id, 'to' => $GLOBALS['user']->userid));
        if (empty($r))
            return false;
        else {
            DB::Update(self::$talbe, $id, array("read" => "Y"));
            return $r;
        }
    }

    public static function get($offset = 0, $size = PAGE_SIZE) {
        $r = DB::LimitQuery(self::$talbe, array("condition" => array("to" => $GLOBALS['user']->userid, "del" => "N"),
                    "offset" => $offset, "size" => $size));
        return $r;
    }

    public static function del($id) {
        return DB::Delete(self::$talbe, array("to" => $GLOBALS['user']->userid, "id" => $id));
    }

    public static function getsend($offset = 0, $size = PAGE_SIZE) {
        $r = DB::LimitQuery(self::$talbe, array("condition" => array("from" => $GLOBALS['user']->userid),
                    "offset" => $offset, "size" => $size));
        return $r;
    }

}

/* End of file Msg */


